<?php
namespace Admin\Controller;
use Think\Controller;
class OrdersController extends Controller {
    public function index(){
        //实例化订单表
        $orders = D('orders');
        $orderid = I('post.OrderId');
        // dump($orderid);?\
        // 判断是否有进行搜索
        if($orderid){
            //如果有，那就进行模糊查询
            $list = $orders->orders_like($orderid); 
        }else{
            $list = $orders->orders_sec();
        }
        $this->assign('list',$list['list']);
        $this->assign('show',$list['show']);
        // dump($list);
        //显示后台模板      
       $this->display();
    }
    //显示订单详情模板
    public function order_detailed(){
        //获取订单id和地址表id,订单号
        $addressid = I('get.addressid');
        $orderid = I('get.orderid');
        $OID = I('get.OID');
        // dump($OID);
        //实例化订单详情表
        $orderInfo = M('order_info');
        //实例化地址表
        $address = M('address');
        //查询用户收货地址
        // 设置查询条件
        $map['id'] = ['eq',$addressid];
        //执行查询
        $addlist = $address->where($map)->find();
        //分配地址表数据
        $this->assign('address',$addlist);
        //查询订单详情
        // 设置查询条件
        $map = [];
        $map['orderid'] = ['eq',$orderid];
        //执行查询
        $orderlist = $orderInfo->where($map)->select();
         //获取订单商品数量
        $num = count($orderlist);
        // dump($orderlist);
        //实例化goods表
        $goods = M('goods');
        //循环查询商品信息
        for ($i=0; $i < $num ; $i++) { 
            $map = [];
            $map['id'] = ['eq',$orderlist[$i]['goodsid']];
            $glist = $goods->where($map)->select();
            // dump($glist);
            $orderlist[$i]['picname'] = $glist[0]['pic'];
            $orderlist[$i]['goodsname'] = $glist[0]['goods'];
        }
        // dump($orderlist);

       
        //分配订单详情数据
        $this->assign('Olist',$orderlist);
        //将订单号分配给模板
        $this->assign('OID',$OID);
        $this->display(); 
    }
    //执行发货方法
    public function up_status(){
        $orders = D('orders');
        $res = $orders->status_edit();
        if($res){
            $this->success('发货成功');
        }else{
            $this->error('不能操作已发货订单，作废订单，完成订单');
        }
    }
}